﻿using System;
using System.Collections.Generic;
using Assets.Scripts.DynamicClouds;
using CapturePanorama;
using SizeboxUI;
using UnityEngine;
using UnityEngine.Networking;

// Token: 0x020002B3 RID: 691
public class GameController : MonoBehaviour
{
	// Token: 0x170001C1 RID: 449
	// (get) Token: 0x06000F3D RID: 3901 RVA: 0x000740E0 File Offset: 0x000722E0
	// (set) Token: 0x06000F3E RID: 3902 RVA: 0x000740E7 File Offset: 0x000722E7
	public static Player playerInstance { get; private set; }

	// Token: 0x170001C2 RID: 450
	// (get) Token: 0x06000F3F RID: 3903 RVA: 0x000740EF File Offset: 0x000722EF
	// (set) Token: 0x06000F40 RID: 3904 RVA: 0x000740F7 File Offset: 0x000722F7
	public ClientPlayer spawner { get; private set; }

	// Token: 0x170001C3 RID: 451
	// (get) Token: 0x06000F41 RID: 3905 RVA: 0x00074100 File Offset: 0x00072300
	// (set) Token: 0x06000F42 RID: 3906 RVA: 0x00074108 File Offset: 0x00072308
	public bool paused { get; private set; }

	// Token: 0x170001C4 RID: 452
	// (get) Token: 0x06000F43 RID: 3907 RVA: 0x00074111 File Offset: 0x00072311
	// (set) Token: 0x06000F44 RID: 3908 RVA: 0x00074119 File Offset: 0x00072319
	public bool userIsTyping { get; private set; }

	// Token: 0x170001C5 RID: 453
	// (get) Token: 0x06000F45 RID: 3909 RVA: 0x00074122 File Offset: 0x00072322
	// (set) Token: 0x06000F46 RID: 3910 RVA: 0x0007412A File Offset: 0x0007232A
	public bool gameStarted { get; private set; }

	// Token: 0x170001C6 RID: 454
	// (get) Token: 0x06000F47 RID: 3911 RVA: 0x00074133 File Offset: 0x00072333
	// (set) Token: 0x06000F48 RID: 3912 RVA: 0x0007413B File Offset: 0x0007233B
	public MainView view { get; private set; }

	// Token: 0x170001C7 RID: 455
	// (get) Token: 0x06000F49 RID: 3913 RVA: 0x00074144 File Offset: 0x00072344
	// (set) Token: 0x06000F4A RID: 3914 RVA: 0x0007414C File Offset: 0x0007234C
	public CapturePanorama panorama { get; private set; }

	// Token: 0x06000F4B RID: 3915 RVA: 0x00074158 File Offset: 0x00072358
	private void Awake()
	{
		GameController.Instance = this;
		if (NetworkManager.singleton)
		{
			this.networkManager = NetworkManager.singleton;
		}
		else
		{
			this.networkManager = UnityEngine.Object.Instantiate<NetworkManager>(this.networkManager);
		}
		this.gameStarted = false;
		EventManager.Clear();
		this.pathfinder = new Pathfinder();
		this.sharedKnowledge = new SharedKnowledge();
		base.gameObject.AddComponent<SoundManager>();
		base.gameObject.AddComponent<SimpleSunController>();
		this.panorama = base.gameObject.AddComponent<CapturePanorama>();
		this.SetPausedState(false);
		Layers.Initialize();
		this.view = base.gameObject.AddComponent<MainView>();
		Physics.gravity = new Vector3(0f, -9.8f, 0f);
	}

	// Token: 0x06000F4C RID: 3916 RVA: 0x0007421C File Offset: 0x0007241C
	public void SetPausedState(bool pause)
	{
		this.paused = pause;
		float timeScale = 1f;
		if (pause && !GameController.IsMultiplayer())
		{
			timeScale = 0f;
		}
		Time.timeScale = timeScale;
		GameController.playerInputEnabled = !pause;
	}

	// Token: 0x06000F4D RID: 3917 RVA: 0x0007425B File Offset: 0x0007245B
	public void SetIsTyping(bool pause)
	{
		this.userIsTyping = pause;
	}

	// Token: 0x06000F4E RID: 3918 RVA: 0x00074264 File Offset: 0x00072464
	private void Start()
	{
		if (!GameController.IsMultiplayer())
		{
			NetworkManager.singleton.networkPort = 0;
			NetworkManager.singleton.StartHost();
		}
		else
		{
			base.GetComponent<CenterOrigin>().enabled = false;
			NetworkManagerHUD component = this.networkManager.GetComponent<NetworkManagerHUD>();
			component.showGUI = true;
		}
	}

	// Token: 0x06000F4F RID: 3919 RVA: 0x000742B5 File Offset: 0x000724B5
	private void Update()
	{
		if (IOManager.Instance.isLoadingData && ClientPlayer.Instance != null)
		{
			IOManager.Instance.isLoadingData = false;
			Debug.Log("Loading the data to the scene");
			SavedScenesManager.Instance.ReBuildScene();
		}
	}

	// Token: 0x06000F50 RID: 3920 RVA: 0x000742F5 File Offset: 0x000724F5
	public static bool IsMultiplayer()
	{
		return StateManager.instance.gameSettings.multiplayer;
	}

	// Token: 0x06000F51 RID: 3921 RVA: 0x00074308 File Offset: 0x00072508
	public void RegisterPlayer(ClientPlayer player)
	{
		this.spawner = player;
		string text = StateManager.instance.myData.name;
		if (text == null || text.Length == 0)
		{
			text = IOManager.Instance.GetRandomPlayerModelName();
		}
		this.spawner.CallCmdSpawnPlayer(text);
		StateManager.instance.myData.name = text;
		GameController.playerInputEnabled = true;
		this.gameStarted = true;
	}

	// Token: 0x06000F52 RID: 3922 RVA: 0x00074371 File Offset: 0x00072571
	public void SetPlayerInstance(Player player)
	{
		GameController.playerInstance = player;
		if (this.luaManager != null)
		{
			this.luaManager.UpdatePlayer(GameController.playerInstance);
		}
	}

	// Token: 0x06000F53 RID: 3923 RVA: 0x0007439A File Offset: 0x0007259A
	public void OnPlayerStart()
	{
		if (this.luaManager == null)
		{
			this.luaManager = base.gameObject.AddComponent<LuaManager>();
		}
	}

	// Token: 0x06000F54 RID: 3924 RVA: 0x000743BE File Offset: 0x000725BE
	public static void IncreaseSpeed()
	{
		GameController.globalSpeed /= 1.2f;
		ObjectManager.Instance.UpdateAllSpeeds();
	}

	// Token: 0x06000F55 RID: 3925 RVA: 0x000743DA File Offset: 0x000725DA
	public static void DecreaseSpeed()
	{
		GameController.globalSpeed *= 1.2f;
		ObjectManager.Instance.UpdateAllSpeeds();
	}

	// Token: 0x06000F56 RID: 3926 RVA: 0x000743F6 File Offset: 0x000725F6
	public static void ChangeSpeed(float newSpeed)
	{
		GameController.globalSpeed = newSpeed;
		ObjectManager.Instance.UpdateAllSpeeds();
	}

	// Token: 0x06000F57 RID: 3927 RVA: 0x00074408 File Offset: 0x00072608
	public static void SetSlowDown(bool value)
	{
		GlobalPreferences.SlowdownWithSize.value = value;
		ObjectManager.Instance.UpdateAllSpeeds();
	}

	// Token: 0x06000F58 RID: 3928 RVA: 0x00074420 File Offset: 0x00072620
	public static string ConvertScaleToHumanReadable(float scale)
	{
		scale /= GameController.referenceScale;
		string text;
		if (GlobalPreferences.ImperialMesurement.value)
		{
			scale /= 0.3048f;
			if (scale < 1f)
			{
				scale = (float)((double)scale - Math.Truncate((double)scale)) / 0.08333f;
				if (scale < 0.1f)
				{
					text = " th";
					scale *= 1000f;
				}
				else
				{
					text = " in";
				}
			}
			else
			{
				if (scale <= 5280f)
				{
					text = " ft";
					double num = ((double)scale - Math.Truncate((double)scale)) / 0.08333;
					int num2 = (int)num;
					return scale.ToString("0") + "." + num2.ToString("0") + text;
				}
				scale /= 5280f;
				text = " mi";
			}
		}
		else if (scale >= 1000f)
		{
			text = " km";
			scale /= 1000f;
		}
		else if (scale >= 1f)
		{
			text = " m";
		}
		else if (scale >= 0.01f)
		{
			text = " cm";
			scale *= 100f;
		}
		else
		{
			scale *= 1000f;
			if (scale < 0.1f)
			{
				text = " μm";
				scale *= 1000f;
			}
			else
			{
				text = " mm";
			}
		}
		return scale.ToString("0.00") + text;
	}

	// Token: 0x04001431 RID: 5169
	public static GameController Instance;

	// Token: 0x04001432 RID: 5170
	public NetworkManager networkManager;

	// Token: 0x04001433 RID: 5171
	public Pathfinder pathfinder;

	// Token: 0x04001434 RID: 5172
	public static CloudController cloudController;

	// Token: 0x04001435 RID: 5173
	public static List<GameObject> giantessesOnScene = new List<GameObject>();

	// Token: 0x04001436 RID: 5174
	public static float globalSpeed = 1f;

	// Token: 0x04001437 RID: 5175
	public static float startingSize = 1f;

	// Token: 0x04001438 RID: 5176
	public static float referenceScale = 1f;

	// Token: 0x04001439 RID: 5177
	public static float maxSize = 1000f;

	// Token: 0x0400143A RID: 5178
	public static bool IsMacroMap = false;

	// Token: 0x0400143B RID: 5179
	public static bool playerInputEnabled = false;

	// Token: 0x0400143C RID: 5180
	public SharedKnowledge sharedKnowledge;

	// Token: 0x04001444 RID: 5188
	private LuaManager luaManager;
}
